var modRewrite  = require('connect-modrewrite');
var config = require('./config')();
var browserSync = require('browser-sync').create();


var browser = function () {
    var proxyRule = [
        /*'^/(?!api|vendors|css|scripts|images|fonts|pay/).* /html/index.html [L]',

        // '^/(?!api|view/vendors|view/css|view/scripts|view/images).* /view/html/index.html [L]',

        // '!^/api/(.*)$|\\.js|\\.css$ /html/index.html',
        '^/api/(.*)$ http://gz.weixin.qwan.ren/api/$1 [P]',
        '^/pay/(.*)$ http://gz.weixin.qwan.ren/pay/$1 [P]',*/
    ];
    browserSync.init({
        open:true,
        logFileChanges: false,
        reloadDebounce: 1000,
        startPath:'/pages/',
        port: 3001,
        server: {
            baseDir: config.dev,
            middleware: [
                modRewrite(proxyRule)
            ]
        }
    });

    browserSync.watch(config.dev + '**/*', browserSync.reload);

};
var browser_dist = function () {
    var proxyRule = [
        // '^/(?!api|view/vendors|view/css|view/scripts|view/images).* /view/html/index.html [L]',
        // '^/api/(.*)$ http://gz.weixin.qwan.ren/api/$1 [P]',
    ];
    browserSync.init({
        open:false,
        logFileChanges: false,
        reloadDebounce: 1000,
        startPath:'/pages',
        server: {
            baseDir: config.dist,
            middleware: [
                modRewrite(proxyRule)
            ]
        }
    });
};

module.exports = {
    dev: browser,
    pro: browser_dist
}